package com.thb.pay.manage.web.payment;


import com.thb.pay.api.payment.ChannelConfigTypeServiceApi;
import com.thb.pay.api.payment.vo.req.ChannelConfigTypePageReq;
import com.thb.pay.api.payment.vo.req.ChannelConfigTypeReq;
import com.thb.pay.api.payment.vo.resp.ChannelConfigTypeVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.core.utils.R;
import com.thb.pay.manage.comm.controller.BaseController;
import com.xiaoleilu.hutool.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 渠道类型表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Slf4j
@RestController
@RequestMapping("api/sys/channelConfigType")
public class ChannelConfigTypeController extends BaseController {

    @Autowired
    private ChannelConfigTypeServiceApi channelConfigTypeServiceApi;

    @PostMapping("/list")
    public R list(@RequestBody ChannelConfigTypePageReq pageReq) {
        PageResult<ChannelConfigTypeVo> pageResult = channelConfigTypeServiceApi.findPage(pageReq);
        return R.okData(pageResult);
    }


    @RequestMapping("/allList")
    public R allList() {
        List<ChannelConfigTypeVo> resultDataList = channelConfigTypeServiceApi.findAllList();
        return R.okData(resultDataList);
    }

    @RequestMapping("/get")
    public R get(@RequestParam("id") Long id) {
        ChannelConfigTypeVo resultData = channelConfigTypeServiceApi.getById(id);
        return R.okData(resultData);
    }

    @PostMapping("/add")
    public R add(@RequestBody ChannelConfigTypeReq channelConfigTypeReq) {
        channelConfigTypeServiceApi.add(channelConfigTypeReq);
        return R.ok();
    }


    @PostMapping("/delete")
    public R delete(@RequestBody List<Long> ids) {
        if (CollUtil.isNotEmpty(ids)) {
            channelConfigTypeServiceApi.deleteBatchIds(ids);
        }
        return R.ok();
    }


    @PostMapping("/update")
    public R update(@RequestBody ChannelConfigTypeReq channelConfigTypeReq) {
        channelConfigTypeServiceApi.update(channelConfigTypeReq);
        return R.ok();
    }
}
